<template>
    <div>
        <!-- 站内订票明细报表 -->
        <div class="container">
            <!-- 标题栏 -->
            <div class="headstyple">
                <el-row>
                    <el-col :span="16" class="ticket-title">报表>售票模块-站内订票明细报表</el-col>
                    <el-col :span="2">
                        <button class="check-btn form-btn" @click="check">
                            <img src="../../assets/imgs/operation_btn_icon_chaxun_default.png" alt="" class="btn-img">查询

                        </button>
                    </el-col>
                    <el-col :span="2">
                        <button class="check-btn form-btn" @click="">
                            <img src="../../assets/imgs/operation_btn_icon_xin_default.png" alt="" class="btn-img">新窗口

                        </button>
                    </el-col>
                    <el-col :span="2">
                        <button class="check-btn form-btn" @click="">
                            <img src="../../assets/imgs/operation_btn_icon_dayin_default.png" alt="" class="btn-img">直接打印

                        </button>
                    </el-col>
                    <el-col :span="2">
                        <button class="check-btn form-btn" @click="">
                            <img src="../../assets/imgs/operation_btn_icon_daochu_default.png" alt="" class="btn-img">导出

                        </button>
                    </el-col>
                </el-row>
            </div>
            <div class="bottom-container">
                <el-form :model="formList" :inline="true" class="ticketForm" id="summarySheet">
                    <div>
                        <el-form-item label="售票时间起">
                            <el-date-picker type="datetime" size="mini" class="minipt" default-time="00:00:00"
                                            v-model="formList.starDate" value-format="yyyy-MM-dd-HH:mm:ss"></el-date-picker>
                            止
                            <el-date-picker type="datetime" size="mini" class="minipt" default-time="23:59:59"
                                            v-model="formList.endDate" value-format="yyyy-MM-dd-HH:mm:ss"></el-date-picker>
                            <span><img src="../../assets/imgs/operation_bg_sousuo_default.png" alt="" class="btn-time"
                                       @click="sysdateinfo"></span>
                        </el-form-item>
                        <el-form-item label="订单状态">
                            <el-select size="mini" class="inp" v-model="formList.orderstatus" @change="orderstatuschange">
                                <el-option
                                        v-for="item in orderstatuslist"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value+ ';' +item.label">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </div>
                </el-form>
            </div>
        </div>

        <!--遮罩层-->
        <div class='popContainer' v-show="modelShow"></div>
        <!--弹窗页面部分-->
        <div class="management-modal-win" v-show="modelShow">
            <!-- 标题 -->
            <el-row>
                <el-col :span="24">
                    <img src="../../assets/imgs/operation_bg_biaoti_default.png" alt="" class="lf modal-img">
                    <div class="lf modal-title">{{modalTitle}}</div>
                    <div class="rf close" @click="closeModual()">X</div>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <div class="msg-win">
                        <!-- 修改弹窗 -->
                        <div>
                            <el-row class="driver-container">
                                <el-col>
                                    <div>
                                        <el-table style="width: 100%" :data="DatetableData" height="290px" @row-dblclick="sysdate">
                                            <el-table-column type="index" width="20px"></el-table-column>
                                            <el-table-column prop="date_name" label="名称"></el-table-column>
                                            <el-table-column prop="date_start" label="起始日期"></el-table-column>
                                            <el-table-column prop="date_end" label="结束日期"></el-table-column>
                                            <el-table-column prop="beizhu" label="备注"></el-table-column>
                                        </el-table>
                                    </div>
                                </el-col>
                            </el-row>
                        </div>
                    </div>
                </el-col>
            </el-row>

            <el-row>
                <el-col :span="24">
                    <button class="check-btn rf" @click="closeformwindows"><img
                            src="../../assets/imgs/operation_btn_icon_quxiao_default.png" alt=""
                            class="btn-img">取消
                    </button>
                </el-col>
            </el-row>
        </div>
        <!--  -->
        <div id="test1" v-html="htmlreport" class="container"> </div>

    </div>
</template>
<script>
    import "../../assets/js/jquery.js";
    import FormData from "../../components/common/form";
    import TableData from "../../components/common/tableData";
    import qs from "qs";

    export default {

        data() {
            return {
                formList: {
                    starDate: "",
                    endDate: "",
                    orderstatus:"",
                },
                orderstatuslist:[
                    {
                        value: '',
                        label: ' '
                    },
                    {
                        value: '0',
                        label: '已锁位(未支付)'
                    },
                    {
                        value: '1',
                        label: '已提交(已支付)'
                    },
                    {
                        value: '2',
                        label: '已取消'
                    },
                    {
                        value: '3',
                        label: '已取票'
                    },
                    {
                        value: '4',
                        label: '已退票'
                    },
                    {
                        value: '5',
                        label: '已废票'
                    },
                    {
                        value: '1,3',
                        label: '正常票(提交、取票)'
                    },
                    {
                        value: '1,3,4',
                        label: '正常票 + 已退票'
                    },
                ],

                modelShow: false,
                modalTitle: "",
                DatetableData:"",

                orderstatusitemid: "",
                orderstatusitemname: "",

                htmlreport:"",

            };
        },

        methods: {
            //订单状态回调
            orderstatuschange(item){
                console.log(item);
                this.orderstatusitemid = item.split(';')[0];
                this.orderstatusitemname = item.split(';')[1];
            },
            //获取弹窗
            sysdateinfo(){
                this.getsysdate();
                this.modelShow = true;
                this.modalTitle = "选择日期";
                console.log(this.modelShow);
            },
            //关闭弹窗
            closeModual() {
                this.modelShow = false;
            },
            //关闭弹窗
            closeformwindows() {
                this.modelShow = false;
            },
            //获取弹窗时间数据
            getsysdate(){
                this.DatetableData=[];
                this.$http
                    .post("/sys/customdatescope/list")
                    .then(data => {
                        console.log(data.data);
                        console.log(data.data.list);
                        for(var item of data.data.list){
                            this.DatetableData.push({
                                id:item.id,
                                date_name:item.name,
                                date_start:item.start_date,
                                date_end:item.end_date,
                                beizhu:item.remark,
                            })

                        }
                    })
            },
            //双击获取自定义日期
            sysdate(row, event){
                console.log(row.id);
                console.log(this.DatetableData);
                this.formList.starDate = row.date_start + " 00:00:00";
                this.formList.endDate = row.date_end + " 23:59:59";
                this.modelShow = false;
            },
            //时间处理,获取当天时间
            todayfunction(){
                let now = new Date();
                var nowday = new Date(Date.UTC(now.getFullYear(), now.getMonth(), now.getDate())).toISOString().slice(0, 10);
                this.nowtoday = nowday;
                console.log(nowday);
                this.formList.starDate = nowday +" 00:00:00";
                this.formList.endDate = nowday + " 23:59:59";
            },
            //encodeURI 编码
            check(){
                //通过select的机构选择框，获取其名称
                let parm = '[{"text":"售票时间起:","field":"be_sale","op":"dge","value":"'+this.formList.starDate+'","valuename":"'+this.formList.starDate+'"},' +
                    '{"text":"止:","field":"ed_sale","op":"dle","value":"'+this.formList.endDate+'","valuename":"'+this.formList.endDate+'"},' +
                    '{"text":"订单状态:","field":"order_status","op":"in","value":"'+this.orderstatusitemid+'","valuename":"'+this.orderstatusitemname+'"}]';
                let sqlparm = '{"be_sale":"'+this.formList.starDate+'","ed_sale":"'+this.formList.endDate+'","order_status":"'+this.orderstatusitemid+'"}';
                //编码
                let encodeparm = encodeURIComponent(parm);
                let encodesqlparm = encodeURIComponent(sqlparm);
                //执行查询
                this.getreport(encodeparm, encodesqlparm);

            },
            //查询
            getreport(type1, type2){
                this.htmlreport = "";
                let rpT = "%E5%94%AE%E7%A5%A8%E6%A8%A1%E5%9D%97";
                let rpN = "%E7%AB%99%E5%86%85%E8%AE%A2%E7%A5%A8%E6%98%8E%E7%BB%86%E6%8A%A5%E8%A1%A8";
                this.$http
                    .get(
                        '/reports',
                        {
                            params: {
                                rpType: rpT,
                                rpName: rpN,
                                protype: 98,
                                rpparajson: type1,
                                sqlparajson: type2,
                            }
                        }
                    )
                    .then(data => {
                        console.log(data.data);
                        this.htmlreport = data.data;
                    })
            },

        },
        mounted(){
            this.todayfunction();
        },
    }
</script>
<style scoped>
    @import url('../../assets/css/Report/insuranceDetails.css');

    .check-btn {
        width: 100px;
    }
    .el-form--inline .el-form-item {
        margin-right: 60px;
    }
    #summarySheet .el-date-editor.el-input{
        width:174px!important;
    }
    #summarySheet .el-select>.el-input{
        width:400px!important;
    }

</style>
